<template>
  <div>
    <Search @SearchBtn="SearchBtnFn" />
    <Table
      :table-data="tableData"
      :btn-text="'新增库区'"
      :pagecount="pagecount"
      @TypeChange="TypeChangeFn"
      @TopBtn="TopBtnFn"
      @CurrentChange="CurrentChangeFn"
      @SizeChange="SizeChangeFn"
      @OneBtn="OneBtnFn"
    />
  </div>
</template>

<script>
import { ReservoirDetail } from '@/api'
export default {
  data() {
    return {
      tableData: [],
      CKtype: {},
      pageS: {
        size: 10,
        current: 1
      },
      pagecount: {}
    }
  },
  created() {
    this.ReservoirDetailFn()
  },
  methods: {
    // 渲染数据
    async ReservoirDetailFn(Form) {
      const res = await ReservoirDetail(this.pageS)
      this.pagecount = res.data.data
      res.data.data.records.forEach((item) => {
        const obj = {
          code: item.warehouseName,
          name: item.code,
          type: item.name,
          location: this.$store.state.PublicData.temperatureType[item.temperatureType],
          address: this.$store.state.PublicData.bearingType[item.bearingType],
          status: this.$store.state.PublicData.useType[item.useType],
          surface: this.$store.state.PublicData.status[item.status],
          includedNum: item.personName,
          personName: item.phone,
          phone: item.includedNum,
          updateTime: item.updateTime,
          id: item.id
        }
        this.tableData.push(obj)
      })
    },
    // 搜索
    SearchBtnFn(Form) {
      console.log(Form)
      this.pageS.warehouseName = Form.innerCooder
      this.pageS.name = Form.name
      if (Form.state !== 2 && Form.state !== '') {
        this.pageS.status = Form.state
      }
      this.ReservoirDetailFn()
      this.tableData = []
    },
    TypeChangeFn() { },
    // 新建按钮
    TopBtnFn() {
      this.$router.push({
        path: '/manage-base-info/area/details'
      })
    },
    // 编辑按钮
    OneBtnFn(row) {
      console.log(this.$route)
      this.$router.push({
        path: '/manage-base-info/area/details',
        query: {
          Id: row.id
        }
      })
    },
    // 页数跳转
    CurrentChangeFn(val) {
      this.pageS.current = val
      this.ReservoirDetailFn()
      this.tableData = []
      console.log(val)
    },
    SizeChangeFn(val) {
      this.pageS.size = val
      this.ReservoirDetailFn()
      this.tableData = []
    }
  }
}
</script>

<style>

</style>
